var names = ['aa', 'bb', 'cc']

class Person {
  constructor(name, age) {
    this.name = name
    this.age = age
    this._address = '广州市'
  }
  // 本质上这些方法是放到了原型上
  // 普通的实例方法(是通过创建出来的对象进行访问的)
  eating() {
    console.log(this.name + 'eating~');
  }
  running() {
    console.log(this.name + 'running~');
  }
  // 类的访问器方法(访问修改之前可以进行拦截)
  get address() {
    return this._address
  }
  set address(value) {
    this._address = value
  }
  // 类的静态方法
  // 通过Person.xxx 去访问的
  static randomPerson() {
    var nameIndex = Math.floor(Math.random() * names.length)
    var name = names[nameIndex]
    var age = Math.floor(Math.random() * 100)
    return new Person(name, age)

  }

}

var p1 = new Person('cyj', 18)
var p2 = new Person('why', 38)
p1.eating()
p1.running()
console.log(p1.address);
p1.address = '黄山市'
console.log(p1.address);

// 调用类的静态方法创建
for (var i = 0; i < 5; i++) {
  console.log(Person.randomPerson());
}


// console.log(Object.getOwnPropertyDescriptors(Person.prototype));

var obj = {
  _name: 'why',
  get name() {
    return this._name
  },
  set name(value) {
    this._name = value
  }
}